<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/website/common/base.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>会员注册_${webname }</title>
    <%@ include file="/website/common/common.jsp" %>
    <link href="${webctx }/css/login.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="${webctx}/js/sms.js"></script>
</head>
<style>
    .ft-hd-nav {
        padding-top: 20px;
    }
</style>
<body rmenu="none">
<div id="head-min" class="head-min">
    <a class="logo" href="${ctx }/website/index.jsp"><img style="top:0;" src="${webctx }/images/logo.png"/></a>
    <p class="log-in">会员注册</p>
    <p class="service-phone">客服电话：400-805-5522</p>
</div>
<div id="wrap-main">
    <div class="wid990 reg">
        <div class="main" id="loginpanel">
            <div class="fr regTxt"><a href="${ctx }/user/showlogin">我已经注册，马上去登录</a></div>
            <form action="" method="post" onsubmit="return false">
                <ul class="items">
                    <li class="item">
                        <div class="item-title">用户名：</div>
                        <div class="itemInp-ct">
                            <div class="ipt norWidthIpt"><input id="phone" type="text" class="inp" placeholder="输入手机号码"
                                                                style="height:36px;line-height:36px;"></div>
                        </div>
                        <div class="itemInp-info"></div>
                    </li>
                    <li class="item">
                        <div class="item-title">验证码：</div>
                        <div class="itemInp-ct">
                            <div class="ipt norWidthIpt"><input type="text" id="smscode" class="inp" placeholder="输入验证码"
                                                                style="width:200px;height:36px;line-height:36px;"
                                                                autocomplete="off"></div>
                            <a href="javascript:tosendsms();" class="yzm-btn" id="yzmbtn">发送验证码</a>
                        </div>
                        <div class="itemInp-info"></div>
                    </li>
                    <li class="item">
                        <div class="item-title">密码：</div>
                        <div class="itemInp-ct">
                            <input type="text" name="pwd" onfocus="this.type='password'" class="ipt norWidthIpt"
                                   placeholder="输入密码" style="height:36px;line-height:36px;">
                        </div>
                        <div class="itemInp-info"></div>
                    </li>
                    <li class="item">
                        <div class="item-title">确认密码：</div>
                        <div class="itemInp-ct">
                            <input type="text" name="pwd2" onfocus="this.type='password'" class="ipt norWidthIpt"
                                   placeholder="再次输入密码" style="height:36px;line-height:36px;" autocomplete="off">
                        </div>
                        <div class="itemInp-info"></div>
                    </li>
                    <li class="item">
                        <div class="itemInp-ct padd-l0"><a href="javascript:;" onclick="toregister()" class="reg-btn">立即注册</a>
                        </div>
                    </li>
                    <li class="item">
                        <div class="itemInp-ct">
                            <div class="checkTxt" id="J_checkBtn" style=" line-height:30px;">
                                <span style="display: inline-block;float: none;margin: 0;position: relative;top:3px;right: -2px;"
                                      class="check"></span>
                                我已仔细查阅并同意
                                <a href="javascript:;" id="xieyibtn">《巨达药网用户协议》</a></div>
                        </div>
                    </li>
                </ul>
            </form>
        </div>
        <div class="main hide" id="loginok">
            <div class="loginok"><img src="${webctx }/images/ok.png">恭喜你，注册成功！</div>
            <div class="loginok-btn"><a href="${ctx }">返回首页</a></div>
        </div>
    </div>
</div>
<%@ include file="/website/common/foot-site.jsp" %>
</body>
</html>
<script>
    var can = true;
    $(function () {
        $('#J_checkBtn').click(function () {

            $(this).toggleClass('cur');
            if (this.className.indexOf("cur") != -1) {
                can = false;
                $(".reg-btn").css("background", "#dddddd");
            } else {
                can = true;
                $(".reg-btn").css("background", "#0daeff");
            }
        });

        $(document).keydown(function (event) {
            if (event.keyCode == 13) {
                toregister();
            }
        });

        $("#xieyibtn").click(function (e) {
            window.open(ctx + "/info/info?id=47");
            e.stopPropagation();
        });

        $("form .item input").on("input", function () {
            $(this).parents(".item").find(".itemInp-info").text('');
        });

    })
    var subing = false;
    function toregister() {
        if (!can)return false;
        $(".itemInp-info").text('');
        var checked = true;
        if (!$w.isMobile($("#phone").val())) {
            $("#phone").parent().parent().next().text("请输入正确的手机号");
            checked = false;
        }
        if ($("#smscode").val() == '' || (!(/^\d{4,6}$/).test($("#smscode").val()))) {
            $("#smscode").parent().parent().next().text("请输入正确的验证码");
            checked = false;
        }
        if ($("[name='pwd']").val() == '') {
            $("[name='pwd']").parent().next().text("请输入密码");
            checked = false;
        } else {
            if ($("[name='pwd']").val().length < 6) {
                $("[name='pwd']").parent().next().text("至少六位数密码");
                checked = false;
            }
        }
        if ($("[name='pwd2']").val() == '') {
            $("[name='pwd2']").parent().next().text("请再次输入密码");
            checked = false;
            return false;
        }
        if ($("[name='pwd']").val() != $("[name='pwd2']").val()) {
            $("[name='pwd2']").parent().next().text("两次密码不一致");
            checked = false;
            return false;
        }
        if (!subing && checked) {
            subing = true;
            $(".reg-btn").html('<img src="' + ctx + '/website/images/rr.gif">');
            $w.httpRequest({
                url: apiroot + "/user/register",
                data: {
                    "mobile": $("#phone").val(),
                    "pwd": $("[name='pwd']").val(),
                    "smscode": $("#smscode").val(),
                    "regtype": "phone"
                },
                ok: function (ret) {
                    var user = ret.Data;
                    //$w.setLoginUser(user.userid,user.title,user.phone);
                    try {
                        sessionStorage.setItem("_newreg_", "true");
                        sessionStorage.removeItem("_curUrl_");
                    } catch (e) {
                    }
                    window.location.href = ctx + "/user/showlogin";
                }, fail: function (ret) {
                    if (ret.MsgCode == '2') $("#phone").parent().parent().next().text(ret.MsgDesc);
                    else if (ret.MsgCode == '3') $("#smscode").parent().parent().next().text(ret.MsgDesc);
                    else alert(ret.MsgDesc);
                    return false;
                }, all: function () {
                    subing = false;
                    $(".reg-btn").html('注册');
                }
            })
        }
    }
    function tosendsms() {
        if (!$w.isMobile($("#phone").val())) {
            $("#phone").parent().parent().next().text("请输入正确的手机号");
        } else {
            $w.httpRequest({
                url: apiroot + "/user/checkloginname",
                data: {"loginname": $("#phone").val()},
                ok: function (ret) {
                    $("#phone").parent().parent().next().text("该手机号已被注册");
                }, fail: function (ret) {
                    sendsms($("#phone").val(), 'reg', 'yzmbtn');
                    return false;
                }
            })

        }
    }
</script>
